<template>
  <div class="app-container">
    <div class="law-details">
      <ComSelect @EventChange="changeFn" :options="options"></ComSelect>

      <div class="select-box" style="margin-top: 20px">
        <comForm
          ref="comForm"
          @EventReset="resetFn"
          @EventOnsubmit="queryFn"
          :list="comForm"
        ></comForm>
      </div>

      <ComTable
        :pagination="{ total: paging.total, pageNum: paging.pageNum }"
        :modes="comTableModes"
        :list="tableList"
        :config="{ border: true, width: 200 }"
      >
        <el-table-column
          label="操作"
          width="200"
          align="left"
          #default="{ row }"
        >
          <el-button size="mini" @click="GotoDetailFn(row)">详细</el-button>
          <el-button size="mini">提醒专家</el-button>
        </el-table-column>
      </ComTable>
    </div>
  </div>
</template>

<script>
import ComCard from "../../../../components/comCard.vue";
import ComSelect from "../../../../components/comSelect.vue";
import ComTable from "../../../../components/comTable.vue";
import comForm from "../../../../components/comForm.vue";
import { getupdatedAboutLstApi } from "@/wss/api/lawUpdateReport";
import { getDocGetInfoApi } from "@/wss/api/ContentSupervision";
export default {
  components: { ComSelect, ComCard, comForm, ComTable },
  data() {
    return {
      paging: {
        pageNum: 1,
        pageSize: 10,
        total: 10,
        status: "",
      },
      // 筛选的数据
      options: {
        value: "",
        title: "快速筛选",
        list: [
          {
            value: "0",
            label: "专家未更新",
          },
          {
            value: "1",
            label: "专家已更新",
          },
        ],
      },
      dynamicFilter: {},
      // form的数据
      comForm: {
        modes: [
          {
            formType: "input",
            value: "",
            placeholder: "请输入内容编号",
            label: "内容编号",
            mode: "docNo",
          },
          {
            formType: "input",
            value: "",
            placeholder: "请输入内容标题",
            label: "内容标题",
            mode: "title",
          },
          {
            label: "内容类型",
            formType: "select",
            value: "",
            mode: "docType",
            select: [],
          },
          {
            label: "内容标签",
            formType: "select",
            value: "",
            mode: "label",
            select: [],
          },
          {
            label: "内容性质",
            formType: "select",
            value: "",
            mode: "makeType",
            select: [],
          },
        ],
      },
      // 表格的数据
      tableList: [],
      // 表格列的数据
      comTableModes: [
        {
          type: "selection",
        },
        {
          label: "内容编号",
          mode: "docNo",
        },
        {
          label: "内容类型",
          mode: "docType",
        },
        {
          label: "内容标题",
          mode: "title",
        },
        {
          label: "内容标签",
          mode: "label",
        },
        {
          label: "内容性质",
          mode: "makeType",
          width: 100,
          align: "center",
          isShowTag: true,
          options: [
            {
              l: "全部",
              v: "",
            },
            {
              l: "爬取",
              v: 0,
            },
            {
              l: "平台产出",
              v: 1,
            },
            {
              l: "用户内容公开",
              v: 2,
            },
            {
              l: "用户未公开",
              v: 2,
            },
          ],
        },
        {
          label: "专家",
          mode: "expert",
        },
        {
          label: "创建日期",
          mode: "createTime",
        },
      ],
    };
  },
  methods: {
    GotoDetailFn(row) {
      const { data } = getDocGetInfoApi({ id: row.docId });
      switch (row.docType) {
        case "法条":
          this.$router.push({
            path: "/contentPlatform/laws/laws-details",
            query: { id: data.esId },
          });
          break;
        case "问答":
          this.$router.push({
            path: "/contentPlatform/askAnswer/askAnswer-details",
            query: { id: data.esId },
          });
          break;
        case "政策":
          this.$router.push({
            path: "/contentPlatform/article/article-details",
            query: { id: data.esId },
          });
          break;
        case "头条":
          this.$router.push({
            path: "/contentPlatform/headline/headline-details",
            query: { id: data.esId },
          });
          break;
        default:
          break;
      }
    },
    // 重设
    resetFn() {
      // this.romdom = Math.random();
      this.options.value = "0";
      this.paging.status = "";
    },
    // 查询fn
    queryFn(arr) {
      arr.forEach((item) => {
        for (const key in item) {
          this.paging[key] = item[key];
        }
      });
      this.getContentListFn();
    },
    // 获取列表函数
    async getContentListFn() {
      let result = await getupdatedAboutLstApi(this.paging);
      console.log(result, "相关报告获取list数据");
      if (result.code === 200) {
        this.paging.total = result.total;
        this.tableList = result.rows;
        this.tableList.forEach((item) => {
          // 是否有这个属性
          this.dynamicFilter.makeType ? "" : (this.dynamicFilter.makeType = []);
          this.dynamicFilter.docType ? "" : (this.dynamicFilter.docType = []);
          this.dynamicFilter.label ? "" : (this.dynamicFilter.label = []);
          if (!this.dynamicFilter.docType.includes(item.docType)) {
            this.dynamicFilter.docType.push(item.docType);
          }
          if (!this.dynamicFilter.label.includes(item.label)) {
            this.dynamicFilter.label.push(item.label);
          }
          if (!this.dynamicFilter.makeType.includes(item.makeType)) {
            this.dynamicFilter.makeType.push(item.makeType);
          }
        });

        if (!this.dynamicFilter.docType) {
          return;
        }
        this.comForm.modes.forEach((item) => {
          switch (item.mode) {
            case "makeType":
              item.select = this.arrTransformObj(this.dynamicFilter.makeType);
              break;
            case "docType":
              item.select = this.arrTransformObj(this.dynamicFilter.docType);
              break;
            case "label":
              item.select = this.arrTransformObj(this.dynamicFilter.label);
              break;
            default:
              break;
          }
        });
      }
    },
    // 筛选条件发生改变时候
    changeFn(value) {
      this.$refs.comForm.resetFn();
      this.paging = {
        pageNum: 1,
        pageSize: 10,
        total: 10,
        status: "",
      };
      this.options.value = value;
      this.paging.status = value;
      this.getContentListFn();
    },
  },

  created() {
    this.getContentListFn();
  },
};
</script>

<style lang="scss" scoped>
</style>